package org.jetnuke.dao.sqlserver;

import org.apache.log4j.Logger;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import net.jforum.JForumExecutionContext;
import net.jforum.util.preferences.SystemGlobals;

public class SqlServerBannerDAO extends
		org.jetnuke.dao.generic.GenericBannerDAO {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(SqlServerBannerDAO.class);

	public List selectActiveByTypeOffset(int type, int bannum) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectActiveByTypeOffset(int, int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;
		String q = SystemGlobals.getSql("BannerModel.selectActiveByTypeOffset");
		q = q.replaceAll("#start", String.valueOf(bannum));
		p = JForumExecutionContext.getConnection().prepareStatement(q);
		p.setInt(1, type);
		p.setInt(2, type);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectActiveByTypeOffset(int, int) - end"); //$NON-NLS-1$
		}
		return list;
	}
}
